package com.xh.rufongwallpaper.common.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Swagger配置类
 *
 * @author XH
 */
@Configuration
public class SwaggerConfig {

    /**
     * 创建API分组 - 壁纸相关接口
     */
    @Bean
    public GroupedOpenApi wallpaperApi() {
        return GroupedOpenApi.builder()
                .group("wallpaper")
                .pathsToMatch("/wallpapers/**", "/categories/**")
                .build();
    }

    /**
     * 创建API分组 - 用户相关接口
     */
    @Bean
    public GroupedOpenApi userApi() {
        return GroupedOpenApi.builder()
                .group("user")
                .pathsToMatch("/devices/**", "/favorites/**", "/preferences/**", "/download/**")
                .build();
    }

    /**
     * 创建OpenAPI配置
     */
    @Bean
    public OpenAPI openAPI() {
        return new OpenAPI()
                .info(new Info()
                        .title("如风壁纸 API")
                        .description("如风壁纸应用后端API文档")
                        .version("1.0.0")
                        .contact(new Contact()
                                .name("XH")
                                .email("example@example.com")
                                .url("https://github.com/example"))
                        .license(new License()
                                .name("MIT License")
                                .url("https://opensource.org/licenses/MIT")))
                .components(new Components()
                        .addSecuritySchemes("deviceId", new SecurityScheme()
                                .type(SecurityScheme.Type.APIKEY)
                                .in(SecurityScheme.In.HEADER)
                                .name("X-Device-ID")))
                .addSecurityItem(new SecurityRequirement().addList("deviceId"));
    }
} 